package job;
import bean.UserBehavior;
import function.RankingGenerator;
import function.StatisticsCalculator;
import function.UserBehaviorDao;

import java.sql.Timestamp;
import java.util.List;
public class jobUserBeHavior {
    public static void main(String[] args) {
            // 插入用户行为记录
            UserBehaviorDao behaviorDao = new UserBehaviorDao();
            UserBehavior behavior1 = new UserBehavior("user1", "view", 0, 0, new Timestamp(System.currentTimeMillis()));
            UserBehavior behavior2 = new UserBehavior("user2", "add_to_cart", 2, 0, new Timestamp(System.currentTimeMillis()));
            UserBehavior behavior3 = new UserBehavior("user1", "payment", 0, 100.0, new Timestamp(System.currentTimeMillis()));
            behaviorDao.insertUserBehavior(behavior1);
            behaviorDao.insertUserBehavior(behavior2);
            behaviorDao.insertUserBehavior(behavior3);
            // 计算统计数据
            StatisticsCalculator calculator = new StatisticsCalculator();
            calculator.calculateStatistics();
            // 生成排行榜
            RankingGenerator generator = new RankingGenerator();
            List<RankingGenerator.StatisticEntry> top50Visitors = generator.getTop50Visitors();
            List<RankingGenerator.StatisticEntry> top50AddToCart = generator.getTop50AddToCart();
            List<RankingGenerator.StatisticEntry> top50PaymentAmount = generator.getTop50PaymentAmount();
            // 打印排行榜
            System.out.println("Top 50 Visitors:");
            for (RankingGenerator.StatisticEntry entry : top50Visitors) {
                System.out.println("ID: " + entry.getId() + ", Value: " + entry.getValue());
            }
            System.out.println("Top 50 Add To Cart:");
            for (RankingGenerator.StatisticEntry entry : top50AddToCart) {
                System.out.println("ID: " + entry.getId() + ", Value: " + entry.getValue());
            }
            System.out.println("Top 50 Payment Amount:");
            for (RankingGenerator.StatisticEntry entry : top50PaymentAmount) {
                System.out.println("ID: " + entry.getId() + ", Value: " + entry.getValue());
            }
    }
}
